#! /usr/bin/python

squareNo = set([1, 4, 9, 16, 25, 36, 49, 64, 81])

count = 0
arrange = set()
for i in range(10):
    for j in range(i+1, 10):
	for k in range(j+1, 10):
	    for l in range(k+1, 10):
		for m in range(l+1, 10):
		    for n in range(m+1, 10):
			arrange.add((i, j, k, l, m, n))
			count += 1
	        #print i, j, k, (b1, b2, b3, b4, b5, b6)

count = 0
total = 0
for (a1, a2, a3, a4, a5, a6) in arrange:
    for (b1, b2, b3, b4, b5, b6) in arrange:
	if (a1, a2, a3, a4, a5, a6) == (b1, b2, b3, b4, b5, b6): continue
 	ss = set()
	for a in (a1, a2, a3, a4, a5, a6):
	    for b in (b1, b2, b3, b4, b5, b6):
		ss.add(a*10+b)
		ss.add(b*10+a)
		if a == 6: ss.add(b*10+9)
		if a == 9: 
		   ss.add(60+b)
		   ss.add(b*10+6)
		if b == 6: ss.add(a*10+9)
		if b == 9: 
		   ss.add(60+a)
		   ss.add(a*10+6)		
	if squareNo <= ss: 
	   #print (a1, a2, a3, a4, a5, a6), (b1, b2, b3, b4, b5, b6)
	   total += 1
		
print total/2

